<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
	<meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no,email=no">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-title" content="签到">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>签到</title>
    <link rel="stylesheet" type="text/css" href="../css/base.css?v=201711131200">
    <link rel="stylesheet" type="text/css" href="../css/jquery.step.css?v=201711131200">
    <script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.step.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery-easing/1.4.1/jquery.easing.min.js"></script>
    <script src="https://cdn.bootcss.com/layer/3.0.1/mobile/layer.min.js"></script>
    <script src="https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>
    <script src="../js/common.js?v=20170814001"></script>
    <script src="../js/conf.js?v=20170801001"></script>
	<style>
		html,body{background: #fe4948;}
	</style>
    <script>
       $(function(){
          FastClick.attach(document.body);

            var params = _CZWeb.getUrlParams();
            var brandid = params["brandid"];
            var brandName = (brandid=="feiin"?"wifi":(brandid||"kc")).toUpperCase();
            var allData = {};

 /*           var nowTime = new Date().getTime(),minTime = 1506769200000,maxTime = 1507478400000;
            if(nowTime >= minTime && nowTime < maxTime){
                $('.top').css('background-image','url(../images/sign/top_20171001.jpg)');
    }
*/
            var formatErrorMsg = function(str){
                return str.replace(/{{brand-name}}/g,brandName);
            };
            //弹窗
            var dialog = function(status,str,btn,title,img){
                var dialog = $('<div class="dialog sign-dialog dialog'+status+'"></div>')
                .append('<div class="dialog-close close"></div>')
                .append('<div class="dialog-top">'+(title||'')+'</div>')
                .append(img===false?'':('<div class="dialog-img"'+ (img?('style="background-image:url('+img+')"'):'') +'></div>'))
                .append('<div class="dialog-text">'+(str===false?'':(str?str:(formatErrorMsg(_errorMsg[status])||"发生了系统错误!")))+'</div>');
                var btnBox = $('<div class="button-box flex flex-y-center flex-x-center"></div>');
                if(btn instanceof Array){// [{"text":"asdf","fn":function(){}}]
                    $.each(btn, function(index, val) {
                        if(typeof val === 'object'){
                            var btnid = new Date().getTime() +''+ parseInt(Math.random()*100);
                            var b = $('<div class="dialog-btn close '+(val.simple?'simple':'')+'" id="'+btnid+'">'+val.text+'</div>');
                            if (typeof this.fn === 'function') {
                                $('body').on('click','#'+btnid,function(){
                                    console.log(val.text);
                                    val.fn();
                                });
                            }
                            btnBox.append(b.prop("outerHTML"));
                        }else{
                            btnBox.append('<div class="dialog-btn close">'+(val||'关闭')+'</div>');
                        }
                    });
                }else{
                    if(btn!==false)
                        btnBox.append('<div class="dialog-btn close">'+(btn||'关闭')+'</div>');
                }
                dialog.append(btnBox);
                layer.dialog(dialog.prop("outerHTML"));
            };
           /*进度条*/
           var $step = $("#step");
           $step.step({
               index: 0,
               time: 300,
               title: ["1", "2", "3", "4", "5","6","7"]
           });
           var $index = $step.getIndex();
           console.log($index);

            //获取签到信息
           var signState = function () {
               var loading_index = null,$btn = $('.btn');
               $.ajax({url: _signPageInfoAction,type: 'POST',dataType: 'json',data: params,beforeSend:function(){
                   loading_index = layer.loading();
               }})
                   .done(function(data) {
                       console.log(data);
                       if(data&&data.result==0){
                           allData =data;
                           $('.hasSign').html(data.signin_nums);
                           $('.hasTime').html(7 -data.signin_nums);
                           if(data.egg == 1){
                               $('#eggPic').removeClass('egg1').addClass('egg2');
                           }
                           if(data.signin_type == 0){
                              $btn.removeClass('grayscale');
                              $btn.removeClass('disabled');
                              $step.toStep(data.signin_nums -1);
                           }else if(data.signin_type == 1) {
                               layer.msg('今日已签到');
                               $btn.addClass('grayscale');
                               $btn.addClass('disabled');
                               $step.toStep(data.signin_nums -1);
                           }

                          /* setTimeout(function(){window.open(_CZWeb.getAdspaceUrl_signin(brandid));},1000);*/
                       }else{
                           layer.msg((data&&data.reason)||'系统错误!');
                       }
                   })
                   .fail(function() {
                       layer.msg('请求错误!');
                   }).always(function() {
                   layer.close(loading_index);
               });
           };
           //执行获取签到信息
           signState();
            //签到事件
            var signin = function(){
                var loading_index = null;
                $.ajax({url: _signPageMaoxianAction,type: 'POST',dataType: 'json',data: $.extend(true, params, {signtype:1}),beforeSend:function(){
                    isBegin = true;
                    loading_index = layer.loading();
                }})
                .done(function(data) {
                    console.log(data);
                    if(data&&data.result==0){
                        signState();
                        dialog('jifen','获得'+data.award_integral+'积分',[{"text":"","fn":function(){
                            if(data.signin_nums>=7&&data.eggid!=0&&data.egg==0){
                               $('#zaEgg').show();
                                $step.toStep(data.signin_nums -1);
                            }
                        }}],'签到成功啦!','../img/signD.png');

                    }else{
                        isBegin = false;
                        layer.msg(data.reason);
                    }
                })
                .fail(function() {
                    isBegin = false;
                    layer.msg('请求错误!');
                }).always(function() {
                    layer.close(loading_index);
                });
            };
            $('.btn').on('click',function () {
               signin()

            });
            /*砸蛋*/
            var za = function () {
                var loading_index = null;
                $.ajax({url: _signPageEggAction,type: 'POST',dataType: 'json',data: $.extend(true, params, {eggid:allData.eggid}),beforeSend:function(){
                    loading_index = layer.loading();
                }})
                    .done(function(data) {
                        if(data&&data.result==0){
                            allData.egg = 1;
                            allData.signin_nums = data.signin_nums;
                            $('#zaEgg').hide();
                           $('#eggBreake').show();
                           $('.gift').html('恭喜你得到'+data.goods_name);
                        }else if(data.result == 40){
                            var sum = 7 - (allData.signin_nums);
                            layer.msg('离砸蛋还有'+sum+'天')
                        }else {
                            layer.msg((data&&data.reason)||'系统错误!');
                        }
                    })
                    .fail(function() {
                        layer.msg('请求错误!');
                    }).always(function() {
                    layer.close(loading_index);
                });
            };
            $('.zaBtn').on('click',function () {
             za();
            });
           $('#eggPic').on('click',function () {
               if(allData.egg != 0){
                   layer.msg('彩蛋已被砸开')
               }else {
                  za();
               }
           });
           $('.closeBtn').on('click',function () {
              $(this).parent().parent().hide();
           });
            var initNotice = function(el){
                if (el.html()=="") {
                    el.append('<ul><li></li><li></li></ul>');
                }
                var noticeList = [],noticeIndex = 1,nextNotice = null, noticeUl = el.find('ul');
                //拉取公告信息
                $.post(_noticeAction,$.extend({},params,{module:"",t:1}),function(data){
                    if(data&&data.result==0){
                        //公告显示
                        if(data.broadcast_list){
                            noticeList = data.broadcast_list;
                            if(noticeList.length>0){
                                el.addClass('runing').find('li').eq(0).html(noticeList[0]).end().eq(1).html(noticeList[noticeList.length>0?1:0]);
                            }
                        }
                    }else{
                        layer.msg((data&&data.reason)||'系统错误!');
                    }
                },'json');

                //监控动画结束
                $(document).on('animationEnd webkitAnimationEnd',function(e){
                    var $target = $(e.target);
                    if(e.originalEvent.animationName == "notice-animation" && $target.parent().hasClass('notice')){
                        if(noticeList.length==0){
                            el.removeClass('runing');
                            return;
                        }
                        var lis = noticeUl.find('li');
                        lis.eq(0).html(noticeList[noticeIndex++]);
                        if(noticeIndex>=noticeList.length){
                            noticeIndex=0;
                        }
                        if(nextNotice!=null){
                            noticeList[noticeIndex] = nextNotice;
                            nextNotice = null;
                        }
                        lis.eq(1).html(noticeList[noticeIndex]);
                        el.removeClass('runing');
                        setTimeout(function(){
                            el.addClass('runing');
                        },0);
                    }
                });
                /*签到规则*/
                $('.rule').on('click',function(){
                      $('#signRule').show();
                });
            };

         /*   initSlide();*/
         /*   initInfo();*/
            initNotice($('.notice'));

        /*    $.ajax({
                url: _CZWeb.getAdspaceUrl_signin(brandid),
                dataType: 'json',
            });
*/

        });
	</script>
</head>
<body>
    <div class="page page-sign">
	<!--	<div class="notice"></div>-->
		<div class="rule">签到规则</div>
		<div class="card">
           <img src="../img/signP.png" alt="">
			<p class="title">获得10积分</p>
			<p class="signBtn btn"><span>签到</span></p>
		</div>
		<div class="egg">
			<p>已连续签到<span class="hasSign"></span>天,离彩蛋还剩<span class="hasTime"></span>天</p>
			<div class="eggPic egg1" id="eggPic"></div>
		</div>
		<div id="step" class="step">
		</div>
        <div class="zaEgg" id="zaEgg">
           <div class="dialogEgg">
              <p class="title">恭喜你获得一枚彩蛋</p>
               <div class="eggs"></div>
               <div class="zaBtn"><span>砸开</span></div>
               <div class="closeBtn"></div>
           </div>
        </div>
        <div class="zaEgg" id="eggBreake">
            <div class="dialogEgg">
                <p class="title">恭喜你得奖了</p>
                <div class="eggsB"></div>
                <div class="gift"></div>
                <div class="closeBtn"></div>
            </div>
        </div>
        <div class="zaEgg " id="signRule">
            <div class="dialogEgg rules">
                <p class="title">签到规则</p>
                <p class="txt">1、每次签到后固定获得10积分</p>
                <p class="txt">2、连续签到7天即可获得砸开彩蛋的机会</p>
                <p class="txt">3、如有问题，可联系客服：</p>
                <p class="txt kefu">客服电话：15000351149</p>
                <p class="txt2">活动最终解释权归上海友话网络科技有限公司所有</p>

                <div class="closeBtn"></div>
            </div>
        </div>
	</div>

	<!--<div class="page page-sign">
		<div class="notice"></div>
		<div class="rule">签到规则</div>
		<div class="top"></div>
		<div class="main">
			<div id="slide" class="slide">
				<div class="item sign-buqian" data-signtype="3">
					<div class="title">昨日补签</div>
					<div class="img"></div>
					<div class="des">固定获得5积分</div>
					<div class="btn">补签</div>
				</div>
				<div class="item sign-maoxian" data-signtype="2">
					<div class="title">冒险型签到</div>
					<div class="img flex flex-x-center flex-y-center">
						<div class="num l flex-1"></div>
						<div class="num r flex-1"></div>
					</div>
					<div class="des">随机获得1-50积分不等</div>
					<div class="btn">签到</div>
				</div>
				<div class="item sign-wenzhuan" data-signtype="1">
					<div class="title">稳赚型签到</div>
					<div class="img"></div>
					<div class="des">固定获得5积分</div>
					<div class="btn">签到</div>
				</div>
			</div>
			<div class="jiantou jiantou-l"></div>
			<div class="jiantou jiantou-r"></div>
		</div>
		<div class="info">已连续签到<span class="lianxu">0</span>天，离彩蛋还剩<span class="sheng">7</span>天</div>
		<div class="progress">
			<div class="pig day0"></div>
			<div class="road"></div>
			<div class="egg"></div>
		</div>
	</div>-->

	<script>
	var _hmt = _hmt || [];
	(function() {
	  var hm = document.createElement("script");
	  hm.src = "//hm.baidu.com/hm.js?9b40deeaa9ce094daadf13e0dc1a4729";
	  var s = document.getElementsByTagName("script")[0];
	  s.parentNode.insertBefore(hm, s);
	})();
	</script>
</body>
</html>
